package com.cat.DataStructure04;

import java.util.ArrayList;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-number-of-changes-to-make-binary-string-beautiful/
 * @create 2025/11/30 20:53
 * @since JDK17
 */

public class Solution30 {
    public int minChanges(String s) {
        char[] arr = s.toCharArray();
        int n = arr.length, ans = 0;
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0, j = 0; j < n; i = j) {    // 将连续的一转成数字
            while (j < n && arr[i] == arr[j]) {
                j++;
            }
            list.add(j - i);
        }
        for (int i = 0; i < list.size() - 1; i++) {
            if (list.get(i) % 2 != 0) {
                list.set(i + 1, list.get(i + 1) + 1);
                ans++;
            }
        }

        return ans;
    }
}
